#include <stdio.h>
#include <stdlib.h>

#include "array_sentinel.h"


int comparaisonSets(struct set *s1, struct set *s2)
{
	int i=0, j=0, present=0;
	
	if (s1->size != s2->size)
		return 0;
	
	for (i=0; i< s1->size; ++i)
	{
		for(j=0; j < s2->size;++j)
			if (s1->s[i] != s2->s[j])
				present=1;
		
		if( present == 1)
			present = 0;
		else
			return 0;
		
	}
	
	return 1;
	
}

void affichageSet(struct set *s)
{
	int i;
	
	for (i=0; i< s->size; ++i)
		printf("%c \t", s->s[i]);
	printf("\n");
}

int testAxiome1()
{
	struct set s;
	set__empty(&s);
	
	return set__size(&s) == 0;
	
}

int testAxiome2()
{
	struct set s;
	int size=0;
	set__empty(&s);
	
	size = set__size(&s);
	
	set__add(&s, 'a');
	
	return (size +1) == set__size(&s);
	
}

int testAxiome3()
{
	struct set s;
	int size=0;
	set__empty(&s);
	
	set__add(&s, 'a');
	size = set__size(&s);
	set__add(&s, 'a');
	
	return size == set__size(&s);
}

int testAxiome4()
{
	struct set s;
	set__empty(&s);
	
	return set__is_empty(&s);
}

int testAxiome5()
{
	struct set s;
	set__empty(&s);
	
	set__add(&s, 'a');
	
	return set__is_empty(&s) == 0;
}

int testAxiome6()
{
	struct set s;
	set__empty(&s);
	
	return set__find(&s, 'a') == 0;
}

int testAxiome7()
{
	struct set s;
	set__empty(&s);
	
	set__add(&s, 'a');
	
	return set__find(&s, 'a') == 1;
}

int testAxiome8()
{
	struct set s;
	int result1;
	
	set__empty(&s);
	
	set__add(&s, 'a');
	
	result1 = set__find(&s, 'a');
	
	set__add(&s, 'b');
	
	return result1 == set__find(&s, 'a');
	
}

int testAxiome9()
{
	struct set s, s2;
	
	set__empty(&s);
	
	set__add(&s, 'a');
	
	s2=s;
	
	//~ printf("------- set --------\n");
	//~ affichageSet(&s);
	//~ 
	set__add(&s, 'a');
	
	return comparaisonSets(&s, &s2) == 1;
	
	//~ printf("------- set + set__add(s, a) --------\n");
	//~ affichageSet(&s);
}

int testAxiome10()
{
	struct set s;
	
	set__empty(&s);
	
	set__remove(&s,'a');
	
	return set__is_empty(&s) == 1;
}

int testAxiome11()
{
	struct set s;
	
	set__empty(&s);
	
	set__add(&s, 'a');
	
	set__remove(&s,'a');
	
	return set__is_empty(&s) == 0;
}

int testAxiome13()
{
	struct set s;
	struct set s2;
	struct set sr;
	
	set__empty(&sr);
	set__empty(&s);
	set__empty(&s2);
	
	set__add(&s, 'a');
	
	set__inter(&s, &s2, &sr);
	
	return set__is_empty(&sr) == 1;
}


int testAxiome14()
{
	struct set s;
	struct set s2;
	struct set sr1 ,sr2;
	
	set__empty(&sr1);
	set__empty(&sr2);
	set__empty(&s);
	set__empty(&s2);
	
	set__add(&s, 'a');
	set__add(&s, 'b');
	
	
	set__add(&s2, 'a');
	set__add(&s2, 'c');
	
	
	set__add(&s, 'c');
	set__inter(&s, &s2, &sr1);
	
	
	set__remove(&s, 'c');
	
	set__inter(&s, &s2, &sr2);
	set__add(&sr2, 'c');
	
	return comparaisonSets(&sr1, &sr2) == 1;
	
	//~ printf("------- set__inter(set__add(s, c), s') -------\n");
	//~ affichageSet(&sr1);
	//~ 
	//~ printf("------- set__add(set__inter(s, s'), c) (avec c dans s') -------\n");
	//~ affichageSet(&sr2);
}

int testAxiome15()
{
	struct set s;
	struct set s2;
	struct set sr1 ,sr2;
	
	set__empty(&sr1);
	set__empty(&sr2);
	set__empty(&s);
	set__empty(&s2);
	
	set__add(&s, 'a');
	set__add(&s, 'b');
	
	
	set__add(&s2, 'a');
	
	
	set__inter(&s, &s2, &sr1);
	
	set__add(&s, 'c');
	set__inter(&s, &s2, &sr2);

	
	
	
	printf("------- set__inter(set__add(s, c), s') -------\n");
	affichageSet(&sr1);
	
	printf("------- set__add(set__inter(s, s'), c) (avec c pas dans s') -------\n");
	affichageSet(&sr2);
	
	return comparaisonSets(&sr1, &sr2) == 1;
}


int testAxiome16()
{
	struct set s;
	struct set s2;
	struct set sr1;
	
	set__empty(&sr1);
	set__empty(&s);
	set__empty(&s2);
	
	set__add(&s, 'a');
	set__add(&s, 'b');
	
	set__union(&s, &s2, &sr1);
	
	return set__is_empty(&sr1) == 0;
	
	
}

int testAxiome17()
{
	struct set s;
	struct set s2;
	struct set sr1;
	struct set sr2;
	
	set__empty(&sr2);
	set__empty(&sr1);
	set__empty(&s);
	set__empty(&s2);
	
	set__add(&s, 'a');
	set__add(&s, 'b');
	
	set__add(&s2, 'd');
	
	set__add(&s, 'c');
	set__union(&s, &s2, &sr1);
	
	
	set__remove(&s, 'c');
	set__union(&s, &s2, &sr2);
	set__add(&sr2, 'c');
	
	return comparaisonSets(&sr1,&sr2) == 1;
	
	//~ printf("------- set__union(set__add(s, c), s') -------\n");
	//~ affichageSet(&sr1);
	//~ 
	//~ printf("------- set__add(set__union(s, s'), c) -------\n");
	//~ affichageSet(&sr2);
	
	
}

int main() 
{
	struct set s;
	struct set s2;

	set__empty(&s);
	
	printf(" * set__size(set__empty) = 0 : %d\n", testAxiome1());
	
	printf(" * set__size(set__add(s, c)) (c pas dans s) = set__size(s)+1 : %d\n",testAxiome2());
	
	printf(" * set__size(set__add(s, c)) (c deja dans s) = set__size(s) : %d\n",testAxiome3());
	
	printf(" * set__is_empty(set__empty) = true : %d\n", testAxiome4());
	
	printf(" * set__is_empty(set__add(s, c)) = false : %d \n", testAxiome5());

	printf(" * set__find(set__empty, c) = false : %d\n", testAxiome6());
	
	printf(" * set__find(set__add(s, c), c) = true : %d\n", testAxiome7());
	
	printf(" * set__find(set__add(s, c), c') = set__find(s, c') : %d\n", testAxiome8());
	
	printf(" * set__add(&s, 'a') : %d \n", testAxiome9());
	
	printf(" * set__remove(set__empty, c) = set__empty : %d \n", testAxiome10());
	
	printf(" * set__remove(set__add(s, c), c) = s : %d \n", testAxiome10());
	
	printf(" * set__inter(set__empty, s) = set__empty : %d\n", testAxiome13());
	
	printf(" * set__inter(set__add(s, c), s') = set__add(set__inter(s, s'), c)[if set__find(s',c)=true] : %d \n", testAxiome14());
	
	//printf(" * set__inter(set__add(s, c), s') = set__inter(s, s') [if set__find(s', c)=false] : %d\n", testAxiome15());
	
	
	printf(" * set__union(set__empty, s) = s : %d\n", testAxiome16());
	
	printf(" * set__union(set__add(s, c), s') = set__add(set__union(s, s'), c) : %d \n", testAxiome17());
	
	printf("\n");
	
	return 0;
}
